package com.sds.sweng.swat.miplatform.ui.design.models;

import java.util.ArrayList;
import java.util.List;

import org.codehaus.jackson.annotate.JsonIgnore;

public abstract class MiplatformContainer extends MiplatformComponent {

	protected List<MiplatformComponent> children = new ArrayList<MiplatformComponent>();

	protected int topMargin;
	protected int leftMargin;
	protected int rightMargin;
	protected int bottomMargin;

	public void removeChildren() {
		for (int i=children.size();i>0;i--) {
			removeChild(children.get(i-1));
		}
	}

	public void addChild(MiplatformComponent child) {
		addChild(child, -1);
	}

	public void addChild(MiplatformComponent child, int index) {
		if (index >= 0)
			children.add(index, child);
		else
			children.add(child);

		fireStructureChange(CHILDREN, child);
	}

	public List<MiplatformComponent> getChildren() {
		return children;
	}

	public void removeChild(MiplatformComponent child) {
		children.remove(child);

		fireStructureChange(CHILDREN, child);
	}

	public int getTopMargin() {
		return topMargin;
	}

	public void setTopMargin(int topMargin) {
		this.topMargin = topMargin;
	}

	public int getLeftMargin() {
		return leftMargin;
	}

	public void setLeftMargin(int leftMargin) {
		this.leftMargin = leftMargin;
	}

	public int getRightMargin() {
		return rightMargin;
	}

	public void setRightMargin(int rightMargin) {
		this.rightMargin = rightMargin;
	}

	public int getBottomMargin() {
		return bottomMargin;
	}

	public void setBottomMargin(int bottomMargin) {
		this.bottomMargin = bottomMargin;
	}

	@JsonIgnore
	public int getAreaWidth() {
		return width + 2;
	}

	@JsonIgnore
	public int getContentsWidth() {
		return width - leftMargin - rightMargin;
	}

	public void setChildren(List<MiplatformComponent> children) {
		this.children = children;
	}

}
